//
//  ICMCheckAppearanceDownModel.m
//  ICrEAM
//
//  Created by rainimute on 16/11/9.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMCheckAppearanceDownModel.h"

@implementation ICMCheckAppearanceDownModel

- (void)setupCheckAppearanceDownModelWithAppearanceCheckView:(ICMAppearanceCheckView *)appearanceCheckView{
    
    self.OUT_CHECK_DESC = appearanceCheckView.explainTextView.contentText?:@"";
    
    NSArray *belongTitles = [ICrEAMTool isVW]?@[@"太阳镜",@"随车工具及备胎",@"酒",@"运动器材",@"独立导航",@"香烟"]:@[@"备胎",@"随车工具"];
    NSString *belongText = appearanceCheckView.belongingsTextView.contentText?:@"";
    NSMutableString *belongMutable = [belongText mutableCopy];
    NSInteger belongLength = belongText.length;
    for (NSInteger i=0; i<belongLength; i++) {
        NSRange range = [belongMutable rangeOfString:@" "];
        if (range.length>0) {
            [belongMutable replaceCharactersInRange:range withString:@""];
        }
    }
    if (belongMutable.length>0) {
        belongText = [NSString stringWithFormat:@"%@",belongMutable];
    }else{
        belongText = @"";
    }
    if ([belongText isEqualToString:@""]) {
        self.VHCL_GOODS = @"";
        self.VHCL_GOODS_REMARK = @"";
        return;
    }else{
        NSMutableArray *allBelongs = [[belongText componentsSeparatedByString:@"\n"]mutableCopy];
        NSMutableArray *temp = [NSMutableArray array];
        for (NSString *belong in allBelongs) {
            if ([belong isEqualToString:@""]) {
                [temp addObject:belong];
            }
        }
        [allBelongs removeObjectsInArray:temp];
        NSMutableArray *selectedArray = [NSMutableArray array];
        NSMutableArray *inputArray = [NSMutableArray array];
        for (NSString *belong in allBelongs) {
            [belongTitles containsObject:belong]?[selectedArray addObject:belong]:[inputArray addObject:belong];
        }
        self.VHCL_GOODS = selectedArray.count?[selectedArray componentsJoinedByString:@"@"]:@"";
        self.VHCL_GOODS_REMARK = inputArray.count?[inputArray componentsJoinedByString:@"@"]:@"";
    }
}

@end
